﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO; 
// TEMPORARY BEGIN

using System.Collections.Specialized; 
using System.Configuration; 

// TEMPORARY END

using System.Web;
using System.Web.Security; 
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class dbAdmin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        MembershipUserCollection users = new MembershipUserCollection();
        users=Membership.GetAllUsers(); 

            foreach (MembershipUser user in users) 
            {
                DropDownList1.Items.Add(user.UserName); 
            }
        }
    }


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        MembershipUser find_user = Membership.GetUser(DropDownList1.SelectedValue);
        TextBox1.Text = find_user.Email;
        
    
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MembershipUser find_user = Membership.GetUser(DropDownList1.SelectedValue);
        find_user.Email = TextBox2.Text;
        Membership.UpdateUser(find_user);             
    }
    
    protected void Button3_Click(object sender, EventArgs e)
    {
        NameValueCollection LinkGroups = new NameValueCollection();

        LinkGroups = (NameValueCollection)ConfigurationManager.GetSection("LinkGroups");
        
        foreach (string s in LinkGroups)
        {
            DropDownList2.Items.Add(s); 
        }
        
        string activation_link = LinkGroups["activation_link"];

        Label1.Text = activation_link;

        string redirect_link = LinkGroups["redirect_link"];

        Label2.Text = redirect_link;
       
    }
    protected void Button4_Click(object sender, EventArgs e)
    {

        FileStream fs = new FileStream("C:\\testjq\\cities.txt", FileMode.Open);
        StreamReader sr = new StreamReader(fs);

        while (!sr.EndOfStream)
        {
            string current = sr.ReadLine();

            int index_of_space = current.IndexOf("(");
            int index_of_space1 = current.IndexOf(")");

            string city = current.Substring(0, index_of_space - 1);
            string region = current.Substring(index_of_space + 1, (index_of_space1 - 1) - (index_of_space));

            dbProcessor my_db = new dbProcessor();

            my_db.insert_city(city, region);
            ListBox1.Items.Add(city);
            ListBox1.Items.Add(region);
        }

        sr.Close();
        fs.Close(); 

    }
}